#ifndef __FREE4_H_
#define __FREE4_H_

#ifdef __cplusplus
extern "C"
{
#endif


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

/* Define the linked list structure.  This is used to link free blocks in order
 * of their memory address. */
typedef struct A_BLOCK_LINK
{
    struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */
    size_t xBlockSize;                     /*<< The size of the free block. */
} BlockLink_t;


typedef struct 
{
    BlockLink_t xStart; 
    BlockLink_t *pxEnd;
    uint32_t xTotalBytesRemaining;
    uint32_t xFreeBytesRemaining;
    uint32_t xMinimumEverFreeBytesRemaining;
    uint32_t xNumberOfSuccessfulAllocations;
    uint32_t xNumberOfSuccessfulFrees;
    uint32_t xBlockAllocatedBit;
} _free4_obj_t;


/* export func */

void free4_prvHeapInit( _free4_obj_t *obj, void *addr, size_t total_size );

void * free4_pvPortMalloc( _free4_obj_t *obj, size_t xWantedSize );
void free4_vPortFree( _free4_obj_t *obj, void * pv );

size_t free4_xPortGetTotalHeapSize( _free4_obj_t *obj );
size_t free4_xPortGetFreeHeapSize( _free4_obj_t *obj );
size_t free4_xPortGetMinimumEverFreeHeapSize( _free4_obj_t *obj );

#ifdef __cplusplus
}
#endif

#endif // __FREE4_H_
